package com.ccp.dev.system.controller;

import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.model.SysAuditModelType;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.system.model.SysUser;
import com.ccp.dev.system.model.SysErrorLog;
import com.ccp.dev.system.service.SysErrorLogService;
import com.ccp.dev.core.basic.annotion.Action;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.ModelMap;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 错误日志 信息操作处理控制器
 * 
 * @author y
 * @date 2019-09-24 10:01:54
 */
@Controller
@Action(ownermodel = SysAuditModelType.SYSTEM_SETTING)
@RequestMapping(UrlConstants.PROJECT_ROOT + UrlConstants.PROJECT_MODULE_SYSTEM + "/sysErrorLog")
public class SysErrorLogController extends SysBaseController{
	@Resource
	private SysErrorLogService sysErrorLogService;

    /**
     * 功能描述: 跳转到首页
     *
     * @return: java.lang.String
     * @auther: y
     * @date: 2019-09-24 10:01:54
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_LIST)
    @Action(description="跳转到错误日志首页",exectype = "页面跳转日志")
    public String list() {
        return "sysErrorLog/list";
    }

    /**
     * 功能描述: 跳转到新增页面
     *
     * @return: java.lang.String
     * @auther: y
     * @date: 2019-09-24 10:01:54
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_GET)
    @Action(description="跳转到错误日志详情页面",exectype = "页面跳转日志")
    public String add(HttpServletRequest request,ModelMap modelMap) {
        String id = RequestUtil.getString(request,"id");
        modelMap.put("id",id);
        return "sysErrorLog/get";
    }

    /**
     * 功能描述: 根据主键ID删除数据的通用删除方法
     *
     * @param: id 参数名称必须是"id"
     * @return: java.lang.Object
     * @auther: y
     * @date: 2019-09-24 10:01:54
     */
    @PostMapping(UrlConstants.MODULE_FUNCTION_DELETE)
    @ResponseBody
    @Action(description="根据主键ID删除错误日志数据")
    public Object delete(@RequestParam("id") String id) {
        if (StringUtil.isEmpty(id)) {
            return fail("delete.failure.message");
        }
        int result = sysErrorLogService.delByIdArray(id.split(","));
        return result > 0 ? getResultDataSuccess("delete.success") : getResultDataError("delete.failure");
    }
    /**
     * 功能描述: 根据主键id获取一条数据的通用查询方法
     *
     * @param: id 参数对象必须是"id"
     * @return: java.lang.Object
     * @auther: y
     * @date: 2019-09-24 10:01:54
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_GET)
    @ResponseBody
    @Action(description="根据主键id查询错误日志的一条数据",exectype = "查询日志")
    public Object get(@RequestParam("id") String id) {
        SysErrorLog sysErrorLog = sysErrorLogService.getOneById(id);
        if (null == sysErrorLog) {
            return getResultDataError("get.failure");
        }
        return getResultDataSuccess("get.success",sysErrorLog);
    }

    /**
     * 功能描述: 附带检索条件的分页查询
     *
     * @param: [request] http请求
     * @return: java.lang.Object
     * @auther: y
     * @date: 2019-09-24 10:01:54
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_LIST)
    @ResponseBody
    @Action(description="附带检索条件的分页查询错误日志",exectype = "查询日志")
    public Object list(HttpServletRequest request) {
        QueryFilter queryFilter = new QueryFilter(request, true);
        queryFilter.addFilter("tenantId", ContextUtil.getCurrentUser().getTenantId());
        //分页数据
        List<SysErrorLog> pageDatas = sysErrorLogService.queryList(queryFilter);
        return success(pageDatas, queryFilter.getPageBean().getTotalCount());
    }
}
